package xyz.leepeng.hrm.config;

import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import springfox.documentation.swagger.web.SwaggerResource;
import springfox.documentation.swagger.web.SwaggerResourcesProvider;

import java.util.ArrayList;
import java.util.List;

//用来整合Swagger文档的
@Component
@Primary
public class DocumentationConfig implements SwaggerResourcesProvider {
    @Override
    public List<SwaggerResource> get() {
        List resources = new ArrayList<>();
        //添加所有的微服务的文档资源
        /**
         * 参数:
         * name：自定义的服务的名字
         * location:指定是微服务的路径   /前缀/服务的路由/v2/api-docs   -> 去zuul配置里面找
         */
        resources.add(swaggerResource("系统管理", "/hrm/system/v2/api-docs", "2.0"));
        resources.add(swaggerResource("课程服务", "/hrm/course/v2/api-docs", "2.0"));
        resources.add(swaggerResource("文件服务", "/hrm/file/v2/api-docs", "2.0"));
        resources.add(swaggerResource("搜索服务", "/hrm/es/v2/api-docs", "2.0"));
        resources.add(swaggerResource("用户服务", "/hrm/user/v2/api-docs", "2.0"));

        return resources;
    }

    private SwaggerResource swaggerResource(String name, String location, String version) {
        SwaggerResource swaggerResource = new SwaggerResource();
        swaggerResource.setName(name);
        swaggerResource.setLocation(location);
        swaggerResource.setSwaggerVersion(version);
        return swaggerResource;
    }
}